//
//  MyBillListViewController.m
//  BaseProject
//
//  Created by 王洋 on 2020/7/29.
//  Copyright © 2020 王洋. All rights reserved.
//

#import <BRPickerView.h>

#import "MyBillListCell.h"
#import "MyBillSectionHeader.h"

#import "MyBillListViewController.h"

@interface MyBillListViewController ()<UITableViewDelegate, UITableViewDataSource>

@property (nonatomic, strong) UITableView *tableview;

@property (nonatomic, strong) BRDatePickerView *datePickerView;


@end

@implementation MyBillListViewController

- (void)viewDidLoad {
    [super viewDidLoad];

    [self initView];
}

- (void)initView {
    
    [self.view addSubview:self.tableview];
    
    
    [self.tableview mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.top.right.mas_equalTo(0);
        make.bottom.mas_equalTo(0);
    }];
    
    [self.tableview reloadData];
}

#pragma mark UITableviewDelegate
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
//    return self.dataArray.count;
    return 1;

}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return 30;
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return 50;
}

-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
    return 80;
}

-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
    return CGFLOAT_MIN;
}

#pragma mark sectionheader
-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
    
    MyBillSectionHeader *headView = [[NSBundle mainBundle] loadNibNamed:@"MyBillSectionHeader"owner:nil options:nil].firstObject;
    
    switch (self.type) {
        case MyBillListType_out:{
            headView.typeLab.text = @"支出方式";
        } break;
        case MyBillListType_in:{
            headView.typeLab.text = @"收款方式";
        } break;
        default:
            break;
    }
    
    WEAKSELF
    headView.MyBillSectionHeaderBlock = ^{
      
        [weakSelf.datePickerView show];
    };
    
    return  headView;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    MyBillListCell *cell = [tableView dequeueReusableCellWithIdentifier:@"MyBillListCellID"];
    cell.selectionStyle =UITableViewCellSelectionStyleNone;
//    [cell fillCellWithModel:self.dataArray[indexPath.section].goodsList[indexPath.row]];
    
    return cell;
}

- (UITableView *)tableview {
    if (!_tableview) {
        _tableview = [[UITableView alloc]initWithFrame:CGRectZero style:UITableViewStylePlain];
        _tableview.delegate = self;
        _tableview.dataSource = self;
        _tableview.separatorStyle = UITableViewCellSeparatorStyleNone;
        _tableview.backgroundColor =  UIColorHex(0xf1f1f1);
        
        _tableview.showsHorizontalScrollIndicator = NO;
        _tableview.showsVerticalScrollIndicator = NO;
        
        _tableview.estimatedSectionHeaderHeight = 0;
        _tableview.estimatedSectionFooterHeight = 0;
        _tableview.estimatedRowHeight = 0;
        
        [_tableview registerNib:[UINib nibWithNibName:@"MyBillListCell" bundle:nil] forCellReuseIdentifier:@"MyBillListCellID"];
    }
    return _tableview;
}

- (BRDatePickerView *)datePickerView {
    
    if (!_datePickerView) {
        // 1.创建日期选择器
        _datePickerView = [[BRDatePickerView alloc]init];
        // 2.设置属性
        _datePickerView.pickerMode = BRDatePickerModeYMD;
        _datePickerView.title = @"选择年月日";
        // datePickerView.selectValue = @"2019-10-30";

        _datePickerView.minDate = [NSDate br_setYear:2020 month:1 day:1];
        _datePickerView.maxDate = [NSDate br_setYear:2050 month:12 day:1];
        _datePickerView.isAutoSelect = NO;
        _datePickerView.showToday = YES;
//        _datePickerView.resultBlock = ^(NSDate *selectDate, NSString *selectValue) {
//
//            weakSelf.model.live_startTime = [Utilities getTimestampWithDate:selectDate];
////            [weakSelf.tableview reloadData];
//        };
        
        _datePickerView.changeBlock = ^(NSDate * _Nullable selectDate, NSString * _Nullable selectValue) {
            
        };
    }
    
    return _datePickerView;
}

@end
